#!/usr/bin/env python
# -*- coding: utf-8 -*-

from WSKernel import WSKernel
from Registry import Registry
import sys
import os, configparser
from pymongo import MongoClient

class WSBase:
	def __init__(self):
		config = configparser.ConfigParser()
		config.read(os.getcwd() + '/' + 'config.ini')
		Registry.set('config', config)

		Registry.set('mongo',MongoClient().wr2);
		Registry.set('results_path', os.getcwd() + '/results/')
		Registry.set('data_path', os.getcwd() + '/data/')
		Registry.set('wr_path', os.getcwd())
	def __my_import(self, name):
		sys.path.append('modules/')
		mod = __import__(name)
		the_class = getattr(mod, name)
		return the_class
	def loadModule(self, modulename):
		module = self.__my_import(modulename)
		kernel = WSKernel()
		moduleclass = module(kernel)
		return moduleclass
	def getModulesList(self):
		return list(map(lambda x: os.path.splitext(x)[0], filter(lambda x: x.endswith('py'), os.listdir('modules/'))))